import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池用法2：带缓存的线程池
 */
public class ThreadPoolDemo4 {
    public static void main(String[] args) {
       ExecutorService service= Executors.newCachedThreadPool();
        for (int i = 0; i <1000 ; i++) {
            int finalI = i;
            service.submit(()->{
                System.out.println("i:"+ finalI +"|线程名称:"+Thread.currentThread().getName());
            });
        }
    }
}
